package com.example.designPattern.singleton;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

public class Test {
    public static void main(String[] args) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchFieldException {
        for (Field field : HungrySafeStaticSingleton.class.getFields()) {
            System.out.println(field.getName());
        }
        Class<?>[] declaringClass = HungrySafeStaticSingleton.class.getDeclaredClasses();
        for (Class<?> clazz : declaringClass) {
            System.out.println(clazz.getName());
        }
        System.out.println(declaringClass[0].getName());
        Constructor<?>[] declaredConstructors = declaringClass[0].getDeclaredConstructors();
        for (Constructor<?> constructor : declaredConstructors) {
            if (0 == constructor.getParameterCount()) {
                constructor.setAccessible(true);
                Object o = constructor.newInstance(null);
                Field instance = o.getClass().getDeclaredField("instance");
                instance.setAccessible(true);
                Object o1 = instance.get(o);
                System.out.println(o1);

                System.out.println(o);
            }
        }
        System.out.println(HungrySafeStaticSingleton.getInstance());
//        Class<?> enclosingClass = HungrySafeStaticSingleton.class.getEnclosingClass();
//        System.out.println(enclosingClass.getName());


    }
}
